package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.FoodMapper;
import com.java2207.group1.pojo.Food;
import com.java2207.group1.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author lz
 * @Date 2022/7/26 14:35
 */
@Service("foodService")
public class FoodServiceImpl implements FoodService {

    @Autowired
    private FoodMapper foodMapper;

    @Override
    public LayuiPageVo<Food> foodList(Map<String, Food> params) {
        int page = Integer.parseInt(params.get("page") + "");
        int limit = Integer.parseInt(params.get("limit") + "");

        PageHelper.startPage(page, limit);

        List<Food> list = foodMapper.foodList(params);

        PageInfo<Food> studentPageInfo = new PageInfo<>(list);

        LayuiPageVo<Food> foodLayuiPageVo = new LayuiPageVo<>();

        foodLayuiPageVo.setCode(0);
        foodLayuiPageVo.setMsg("分页列表数据");
        foodLayuiPageVo.setCount(studentPageInfo.getTotal());
        foodLayuiPageVo.setData(studentPageInfo.getList());

        return foodLayuiPageVo;
    }

    @Override
    public int updateFood(Food food) {
        return foodMapper.updateFood(food);
    }

    @Override
    public int addFood(Food food) {
        return foodMapper.addFood(food);
    }

    @Override
    public int deleteFood(Integer id) {
        return foodMapper.deleteFood(id);
    }



}
